package com.ruoyi.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.Food;
import com.ruoyi.system.mapper.FoodMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.FoodSpecMapper;
import com.ruoyi.system.domain.FoodSpec;
import com.ruoyi.system.service.IFoodSpecService;

/**
 * 菜品口味关系Service业务层处理
 * 
 * @author Wxl
 * @date 2022-03-24
 */
@Service
public class FoodSpecServiceImpl implements IFoodSpecService 
{
    @Autowired
    private FoodSpecMapper foodSpecMapper;
    @Autowired
    private FoodMapper foodMapper;
    /**
     * 查询菜品口味关系
     * 
     * @param id 菜品口味关系主键
     * @return 菜品口味关系
     */
    @Override
    public FoodSpec selectFoodSpecById(Long id)
    {
        return foodSpecMapper.selectFoodSpecById(id);
    }

    /**
     * 查询菜品口味关系列表
     * 
     * @param foodSpec 菜品口味关系
     * @return 菜品口味关系
     */
    @Override
    public List<FoodSpec> selectFoodSpecList(FoodSpec foodSpec)
    {
        return foodSpecMapper.selectFoodSpecList(foodSpec);
    }

    /**
     * 新增菜品口味关系
     * 
     * @param foodSpec 菜品口味关系
     * @return 结果
     */
    @Override
    public int insertFoodSpec(FoodSpec foodSpec)
    {
        foodSpec.setCreateTime(DateUtils.getNowDate());
        Long foodId = foodSpec.getFoodId();
        Food food = foodMapper.selectOne(new QueryWrapper<Food>().eq("id", foodId));
        food.setFoodSpecId(foodSpec.getSpecParent().toString());
       foodMapper.updateById(food);
        return foodSpecMapper.insertFoodSpec(foodSpec);
    }

    /**
     * 修改菜品口味关系
     * 
     * @param foodSpec 菜品口味关系
     * @return 结果
     */
    @Override
    public int updateFoodSpec(FoodSpec foodSpec)
    {
        foodSpec.setUpdateTime(DateUtils.getNowDate());
        return foodSpecMapper.updateFoodSpec(foodSpec);
    }

    /**
     * 批量删除菜品口味关系
     * 
     * @param ids 需要删除的菜品口味关系主键
     * @return 结果
     */
    @Override
    public int deleteFoodSpecByIds(Long[] ids)
    {
        return foodSpecMapper.deleteFoodSpecByIds(ids);
    }

    /**
     * 删除菜品口味关系信息
     * 
     * @param id 菜品口味关系主键
     * @return 结果
     */
    @Override
    public int deleteFoodSpecById(Long id)
    {
        return foodSpecMapper.deleteFoodSpecById(id);
    }
}
